package demo1218.homework;

import java.util.Calendar;
import java.util.Scanner;

/*

 */
public class Demo_01 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入一个年份:");//2020
        int year = scan.nextInt();
        System.out.println("请输入一个月份:");//12
        int month = scan.nextInt();
        Calendar cal = Calendar.getInstance();
        cal.set(year, month - 1, 1);//2020 12 1
        System.out.println("日\t一\t二\t三\t四\t五\t六");
        int maxDay = 1;
        int week = cal.getActualMaximum(Calendar.WEEK_OF_MONTH);
        //控制行数 由当前这个月总共有多少周决定
        for (int i = 0; i <week; i++) {
            // 打印列数
            for (int j = 1; j < 8; j++) {
                if (cal.get(Calendar.DAY_OF_WEEK) == j &&
                        cal.getActualMaximum(Calendar.DATE) >= maxDay) {
                    System.out.print(cal.get(Calendar.DATE) + "\t");
                    cal.add(Calendar.DATE, 1);//2020 1 1
                    maxDay++;
                } else {
                    System.out.print("--\t");
                }
            }
            System.out.println();
        }
    }
}
